package at.fhj.itm10.ticketmaster.beans;

import java.util.HashMap;

import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import javax.annotation.ManagedBean;
import javax.annotation.PostConstruct;
import javax.faces.bean.SessionScoped;
import javax.faces.event.ValueChangeEvent;

import at.fhj.itm10.ticketmaster.services.CartService;
import at.fhj.itm10.ticketmaster.services.ServiceFactory;

/**
 * @author Martin Kropf, Wolfgang Schrattner, Reinhard Rebernig, Gabi Grüner
 * @since Jänner 2013
 */

@ManagedBean
@SessionScoped
public class CartBean{
	
	private CartService cartservice;
	
	public CartBean() {
		init();
		//cartservice.setTotalPrice(0.0);
		cartservice.setTotalTicketCount(0);
	}
	
	@PostConstruct
	public void init(){
		ServiceFactory servicefactory = new ServiceFactory();
		cartservice = servicefactory.getCartService();
		
	}
	
	public void valueChangeMethod(ValueChangeEvent e) {
		setTicketQuantity((String) e.getNewValue());
	}
	
	public Map<String, Object> getQuantities(){	
		return cartservice.getQuantities();
	}

	/*
	 * add tickets to card and evaluate if amount of tickets is not to high
	 */
	
	public Boolean addToCart(String id) {
		return cartservice.addToCard(id);
	}
	
	
	/*
	 *  get value of ticketamountisFaild
	 */
	public Boolean getticketamountisFaild() {
		return cartservice.getticketamountisFaild();
	}
		
	public void addTicketPrice(double singlePrice, int quantity) {
		cartservice.addTicketPrice(singlePrice, quantity);
	}
	
	/*
	 *  get total price of all items in cart
	 */
	public String getTotalPrice() {
		return cartservice.getTotalPrice();
	}

	/*
	 * removes Tickets from the cart
	 */
	public String removeFromCart(String id) {
		return cartservice.removeFromCart(id);
	}

	public void emptyCart() {
		cartservice.emptyCart();
	}

	public HashMap<String, Integer> showTickets() {
		return cartservice.showTickets();
	}
	
	
	public List<Entry<String, Integer>> getTicketsList() {
		return cartservice.getTicketsList();
	}

	public int getTotalTicketCount() {
		return cartservice.getTotalTicketCount();
	}

	public void setTotalTicketCount(int totalTicketCount) {
		cartservice.setTotalTicketCount(totalTicketCount);
	}

	public String getTicketQuantity() {
		return cartservice.getTicketQuantity();
	}

	public void setTicketQuantity(String ticketQuantity) {
		cartservice.setTicketQuantity(ticketQuantity);
	}
		
}
